/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package engine.game.combat.ability.filters;

import engine.entities.Entity;
import engine.entities.Mob;
import engine.game.Game;
import engine.game.gfx.Screen.ScreenSelectFilter;
import engine.game.level.Level;
import java.awt.Point;

/**
 *
 * @author NathanT
 */
public class AdjacentEnemyFilter implements ScreenSelectFilter {

    private Game game;
    
    public AdjacentEnemyFilter() {
        this.game = Game.getGlobalGame();
    }
    
    @Override
    public boolean acceptPoint(Level level, Point p) {
        Entity ent = level.entityAt(p);
            if ((ent == null) || !(ent instanceof Mob)) {
                return false;
            }
            Mob mob = (Mob) ent;
            if (mob.isFriendsWith(game.getActivePlayer())) {
                return false;
            }
            Point player = game.getActivePlayer().getCoords();
            if (p.x == player.x) {
                return Math.abs(p.y - player.y) == 1;
            }
            else if (p.y == player.y) {
                return Math.abs(p.x - player.x) == 1;
            }
            return false;
    }
    
}
